package algorithm.easy;

public class Solution58 {

    ////输入：s = "   fly me   to   the moon  "
    ////输出：4
    public static int lengthOfLastWord(String s) {
        String str = s.trim();
        int i=str.length()-1;
        int count = 0;
        while(i>0){
            if(str.charAt(i)==' '){
                break;
            }else{
                count++;
            }
            i--;
        }
        return count;
        /*String[] str = s.split(" ");
        if(str.length==0){
            return -1;
        }
        return str[str.length-1].length();*/
    }

    public static void main(String[] args){
        String s = "   fly me   to   the moon  ";
        System.out.println(lengthOfLastWord(s));
    }
}
